package com.lzh.controller;

import com.lzh.bean.*;
import com.lzh.common.bean.PageBean;
import com.lzh.common.bean.ResultBean;
import com.lzh.common.controller.BaseController;
import com.lzh.domian.AjaxResult;
import com.lzh.query.SupplierQuotationQuery;
import com.lzh.service.SupplierQuotationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "供应商报价管理")
@RestController
@RequestMapping("/api")
public class SupplierQuotationController extends BaseController {

    @Autowired
    private SupplierQuotationService supplierQuotationService;

    /**\
     * 查询供应商报价列表
     * @param supplierQuotationQuery
     * @return
     */
    @ApiOperation("供应商报价列表")
    @PutMapping("/supplierQuotation/list")
    public ResultBean querySupplierQuotation(@RequestBody SupplierQuotationQuery supplierQuotationQuery) {
        PageBean query = supplierQuotationService.query(supplierQuotationQuery);
        return success("供应商报价列表",query);
    }


    /**
     * 根据id查询报价单中的相关信息
     * @param id
     * @return
     */
    @GetMapping("/supplierQuotation/{id}")
    @ApiOperation("根据报价单id查询报价单")
    public AjaxResult querySupplierQuotation(@PathVariable("id") int id) {
        Map map = supplierQuotationService.queryByid(id);
        return AjaxResult.success("报价信息",map);
    }


    /**
     * 保存供应商报价单（产品询价）
     * @param supplierQuotationCPXJ
     * @return
     */
    @PostMapping("/supplierQuotation/cpxj")
    @ApiOperation("保存供应商报价单（产品询价）")
    public AjaxResult saveSupplierQuotationCPXJ(@RequestBody SupplierQuotationCPXJ supplierQuotationCPXJ) {
        int i = supplierQuotationService.saveSupplierQuotationCPXJ(supplierQuotationCPXJ);
        String tmp = i > 0 ?"保存成功":"保存失败";
        return AjaxResult.success("保存产品询价报价单",tmp);
    }

    /**
     * 保存供应商报价单（筛网询价）
     * @param supplierQuotationSWXJ
     * @return
     */
    @PostMapping("/supplierQuotation/swxj")
    @ApiOperation("保存供应商报价单（筛网询价）")
    public AjaxResult saveSupplierQuotationSWXJ(@RequestBody SupplierQuotationSWXJ supplierQuotationSWXJ) {
        int i = supplierQuotationService.saveSupplierQuotationSWXJ(supplierQuotationSWXJ);
        String tmp = i > 0 ?"保存成功":"保存失败";
        return AjaxResult.success("保存筛网报价单",tmp);
    }

    /**
     * 保存供应商报价单（筛网询价）
     * @param supplierQuotationTGXJ
     * @return
     */
    @PostMapping("/supplierQuotation/tgxj")
    @ApiOperation("保存供应商报价单（托辊询价）")
    public AjaxResult saveSupplierQuotationTGXJ(@RequestBody SupplierQuotationTGXJ supplierQuotationTGXJ) {
        int i = supplierQuotationService.saveSupplierQuotationTGXJ(supplierQuotationTGXJ);
        String tmp = i > 0 ?"保存成功":"保存失败";
        return AjaxResult.success("保存托辊报价单",tmp);
    }


    /**
     * 改变订单状态
     * @param changeStatus
     * @return
     */
    @PutMapping("/supplierQuotation/status")
    @ApiOperation("改变订单状态")
    public AjaxResult changeStatus(@RequestBody ChangeStatus changeStatus){
        int i = supplierQuotationService.changeStatus(changeStatus);
        String tmp = i > 0 ?"改变成功":"改变失败";
        return AjaxResult.success("改变订单状态",tmp);
    }

    /**
     * 保存原因
     * @param supplierQuotation
     * @return
     */
    @ApiOperation("保存供应商修改申请")
    @PutMapping("/supplierQuotation/reason")
    public AjaxResult saveReason(@RequestBody SupplierQuotation supplierQuotation){
        int i = supplierQuotationService.saveReason(supplierQuotation);
        String tmp = i > 0 ?"修改成功":"修改失败";
        return AjaxResult.success("保存供应商修改申请",tmp);
    }
}
